package com.example.test.advice.第七章_泛型和反射.建议106_动态代理可以使代理模式更加灵活.dynamic;

import java.lang.reflect.Proxy;

//动态代理
public class Client {

    public static void main(String[] args) {
        Subject subject = new RealSubject();
        SubjectHandler subjectHandler = new SubjectHandler(subject);

        ClassLoader classLoader = subject.getClass().getClassLoader();
        //动态代理
        Subject proxy = (Subject) Proxy.newProxyInstance(classLoader,subject.getClass().getInterfaces(),subjectHandler);
        proxy.request();
    }
}
